import 'package:shared_preferences/shared_preferences.dart';

class Sp {
  static const preFixkey = 'xfg_12_1';
  static const userKey = 'video_app';
  static const uuid = 'uuid_';
  static const qing = 'qing_12';
  static const qing_pass = 'qing_pass';
  static const agree_text = 'agree_tae1xtd';
  static const gxing = 'gxing';

  final isProd = bool.fromEnvironment('dart.vm.product');

  static const isOpenCheckLogin = true;

  //构建key
  buildKey(key) {
    return preFixkey + (isProd ? 'release' : 'degub') + key;
  }

  //获取本地存储
  getSp(key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.get(buildKey(key));
  }

  //设置本地存储
  setSp(key, value) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString(buildKey(key), value.toString());
  }

  //设置本地存储
  remove(key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.remove(buildKey(key));
  }

  checkIsLogin() async {
    var login = await getSp(userKey);
    if (login == '' || login == null) {
      return isOpenCheckLogin;
    }
    return false;
  }
}
